package com.czk.variabledeployment;

import com.czk.pojo.Holiday;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author ChenZhangKun
 * @Date 2020/9/11 17:25
 */
@SuppressWarnings("all")
public class CompleteInstance {
    public static void main(String[] args) {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 得到任务
        TaskService taskService = processEngine.getTaskService();
        // 执行任务查询
        Task task = taskService.createTaskQuery().processDefinitionKey("leave")
                .taskAssignee("陈彰坤").singleResult();
        // 执行任务
        Holiday holiday=new Holiday();
        holiday.setBeginTime(new Date());
        holiday.setNum(5.0f);
        holiday.setHolidayName("陈彰坤");
        holiday.setId(1);
        holiday.setReason("休息");
        holiday.setType("调休");
        Map<String,Object> map=new HashMap<>(10);
        map.put("holiday",holiday);
        // 局部变量，当前任务执行完毕后则不生效,区别则是设置方法后面加local
        // taskService.setVariablesLocal();
        if (task!=null){
            taskService.complete(task.getId(),map);
            System.out.println("执行任务成功");
        }else {
            System.out.println("没有任务");
        }

    }
}
